const { By, until } = require('selenium-webdriver')

exports.autoApprove = async function (driver, options) {
  console.log('自动审批的任务地址--' + options.url)
  await driver.get(options.url)
  let agreeBtn = await driver.wait(until.elementLocated(By.css('input[name=btnApply1],input[id=approve-model-agree]')), 10000)
  console.log('点击同意按钮')
  agreeBtn.click()

  if (options.jobType === 'fl_llcp_bm') {
    console.log('流量产品确认按钮')
    let okBtn =  await driver.wait(until.elementLocated(By.css('.messager-button a:first-of-type')), 10000)
    okBtn.click()
  } else {
    console.log('等待确认框')
    // Wait for the alert to be displayed
    await driver.wait(until.alertIsPresent(), 10000)
    // Store the alert in a variable
    let alert = await driver.switchTo().alert()
    console.log('点击确认')
    // Press the accept button
    await alert.accept()
    console.log('审批结束')
  }
}
